Skip to main content
Version: Next

compareFuncsSync

With this method, you can compare the execution time of several functions and get complete information from it

Params

compareFuncsSync(runtimeCount = 5, ...inputFunctions) ;
  • runtimeCount → The number of times you want input functions to be executed and its time taken
  • inputFunctions → The functions we want to compare their execution time with each other and compare

Returns

<Promise>{
firstRuntimes: {
fastest: [ [Function: inpFunc3], 0.00604 ],
slowest: [ [Function: inpFunc1], 0.07471 ],
rank: [ [Array], [Array], [Array] ]
},
multiRuntimes: {
fastestRun: [ [Function: inpFunc1], 0.00033 ],
slowestRun: [ [Function: inpFunc2], 0.00204 ],
fastestAverage: [ [Function: inpFunc3], 0.00036 ],
slowestAverage: [ [Function: inpFunc2], 0.00085 ],
result: [ [Array], [Array], [Array] ]
}
}
  • Object.firstRuntimes → Comparison of functions in the first run

  • Object.firstRuntimes.fastest → Fastest execution time among functions

  • Object.firstRuntimes.slowest → Slowest execution time among functions

  • Object.firstRuntimes.rank → Execution time of all functions in the order of fastest to slowest

  • Object.multiRuntimes → Comparison of functions in the next several times of execution (by the number of runtimeCount)

  • Object.multiRuntimes.fastestRun → Fastest execution time among functions

  • Object.multiRuntimes.slowestRun → Slowest execution time among functions

  • Object.multiRuntimes.fastestAverage → Fastest execution time among functions

  • Object.multiRuntimes.slowestAverage → Slowest execution time among functions

  • Object.multiRuntimes.result → Execution times of each function(like getMultiRuntimeSync())

Usage

const inpFuncSync1 = async () => {
return await new Promise((resolve, reject) => {
setTimeout(() => {
resolve(true);
}, 2000);
});
};

const inpFuncSync2 = async () => {
return await new Promise((resolve, reject) => {
setTimeout(() => {
resolve(true);
}, 500);
});
};

const inpFuncSync3 = async () => {
return await new Promise((resolve, reject) => {
setTimeout(() => {
resolve(true);
}, 3000);
});
};

const testFunc = async () => {
const res = await compareFuncsSync(5,inpFuncSync1,inpFuncSync2,inpFuncSync3);
console.log(res);
/*
res = {
firstRuntimes: {
fastest: [ [AsyncFunction: inpFuncSync2], 501.66879 ],
slowest: [ [AsyncFunction: inpFuncSync3], 3001.94833 ],
rank: [ [Array], [Array], [Array] ]
},
multiRuntimes: {
fastestRun: [ [AsyncFunction: inpFuncSync2], 501.0025829999995 ],
slowestRun: [ [AsyncFunction: inpFuncSync3], 3001.390166 ],
fastestAverage: [ [AsyncFunction: inpFuncSync2], 501.01521 ],
slowestAverage: [ [AsyncFunction: inpFuncSync3], 3001.36293 ],
result: [ [Array], [Array], [Array] ]
}
}
*/
};
testFunc();